﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DAO;

namespace FDeal.WUC
{
    public partial class WUC_Login : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["isLogin"] == null || (bool)Session["isLogin"] == false)
                    setDangNhap(false);
                else
                    setDangNhap(true);
            }
        }
        private void setDangNhap(bool p)
        {
            pnDangNhap.Visible = !p;
            pnDangXuat.Visible = p;
        }
        protected void btOkLogin_Click(object sender, EventArgs e)
        {
            ThongTinTaiKhoanBUS thongTinTaiKhoangBUS = new ThongTinTaiKhoanBUS();
            THONGTINTAIKHOAN thongTinTaiKhoang = thongTinTaiKhoangBUS.KiemTraDangNhap(tbUserName.Text, tbPassword.Text);
            if (thongTinTaiKhoang == null)
            {
                lbTenUserName.Text = "Đăng nhập sai tên hoặc password.";
            }
            else
            {
                lbTenUserName.Text = thongTinTaiKhoang.TENDANGNHAP;
                Session["isLogin"] = true;
                Session["crUser"] = thongTinTaiKhoang;
                setDangNhap(true);
            }
        }
    }
}